package  ru.javadevelop.vegetarian.adapters;

import android.app.Application;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import ru.javadevelop.vegetarian.R;
import ru.javadevelop.vegetarian.model.Category;

import java.util.ArrayList;


public class CategoriesDataAdapter extends ArrayAdapter<Category> {
    int layoutResourceId;
    Context _context;

    private static ArrayList<Category> categories;

    // Конструктор
    public CategoriesDataAdapter(Context context, int layoutResourceId) {
        super(context, layoutResourceId, Category.getAll());
        categories = Category.getAll();
        this.layoutResourceId = layoutResourceId;
        this._context = context;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null)
        {

            LayoutInflater inflater = (LayoutInflater)((_context).getSystemService(Context.LAYOUT_INFLATER_SERVICE));
            convertView = inflater.inflate(layoutResourceId, parent, false);
            TextView textView = (TextView)convertView.findViewById(R.id.categoryName);
//            holder = new WeatherHolder();
//            holder.imgIcon = (ImageView)row.findViewById(R.id.imgIcon);
//            holder.txtTitle = (TextView)row.findViewById(R.id.txtTitle);
//            row.setTag(holder);
            textView.setText(categories.get(position).name);
        }
        else
        {
//            holder = (WeatherHolder)row.getTag();
        }

        return (convertView);
    }

    // возвращает содержимое выделенного элемента списка
    public Category GetItem(int position) {
        return categories.get(position);
    }



}